package com.java.service;

import com.java.dao.EnterGoodMapper;
import com.java.dao.EnterGoodOkMapper;
import com.java.pojo.EnterGood;
import com.java.pojo.EnterGoodOk;
import com.java.pojo.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EnterGoodOkServiceImpl implements EnterGoodOkService {

    @Autowired
    private EnterGoodOkMapper enterGoodOkMapper;


    @Override
    public int Add(EnterGoodOk enterGoodOk) {
        return enterGoodOkMapper.Add(enterGoodOk);
    }

    @Override
    public EnterGoodOk getEnterGoodOkBydocument2(String document2) {
        return enterGoodOkMapper.getEnterGoodOkBydocument2(document2);
    }

    //总个数
    @Override
    public Integer getCount(String document2,Integer ok) {
        return enterGoodOkMapper.getCount(document2,ok);
    }

    @Override
    public Page<EnterGoodOk> getPageByPage(Integer a, String document2) {
        int b=4;//显示条数
        Page<EnterGoodOk> page=new Page<>();
        page.setCurryPage(a);//设置当前页码
        page.setRows(b);//设置每页显示的条数
        Integer count = enterGoodOkMapper.getCount(document2,1);//总条数
        page.setTotalCount(count);//总条数
        int start=(a-1)*b;/*开始的索引*/
        List<EnterGoodOk> list = enterGoodOkMapper.getListEnterGoodsByPage(start, b, document2,1);
        page.setList(list);/*赋值list*/
        int totalPae=count % b==0 ? count / b : (count / b)+1;
        page.setTotalPae(totalPae);/*设置总页数*/
        if(page==null){
            page=null;
        }
        return page;
    }

    @Override
    public Page<EnterGoodOk> getPageByPage2(Integer a, String document2) {
        int b=4;//显示条数
        Page<EnterGoodOk> page=new Page<>();
        page.setCurryPage(a);//设置当前页码
        page.setRows(b);//设置每页显示的条数
        Integer count = enterGoodOkMapper.getCount(document2,0);//总条数
        page.setTotalCount(count);//总条数
        int start=(a-1)*b;/*开始的索引*/
        List<EnterGoodOk> list = enterGoodOkMapper.getListEnterGoodsByPage(start, b, document2,0);
        page.setList(list);/*赋值list*/
        int totalPae=count % b==0 ? count / b : (count / b)+1;
        page.setTotalPae(totalPae);/*设置总页数*/
        return page;
    }

    @Override
    public int del(Integer eid) {
        return enterGoodOkMapper.del(eid);
    }
}
